package com.fs.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fs.mapper.ProcurementMapper;
import com.fs.pojo.Sto;
import com.fs.service.ProcurementService;
import com.fs.vo.Condition;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author 刘伟
 * @fileName ProcurementServiceImpl
 * @date 2024/10/15 9:19
 * @description
 **/
@Service
public class ProcurementServiceImpl implements ProcurementService {
    @Resource
    ProcurementMapper procurementMapper;
    /**
     * 条件查询获取采购清单列表
     *
     * @param condition
     * @return
     */

    @Override
    public PageInfo<Sto> getProcurementList(Condition<Sto> condition) {
        PageHelper.startPage(condition.getPage(), condition.getCount());
        List<Sto> list = procurementMapper.getProcurementList(condition);
        return new PageInfo<>(list);
    }
    /**
     * 添加采购清单，根据传入的对象直接添加
     * @param sto
     * @return
     */
    @Override
    public Integer addProcurement(Sto sto) {
        return procurementMapper.insert(sto);
    }

    /**
     * 修改某条采购清单，根据传入的对象的id自动进行修改
     * @param sto
     * @return
     */
    @Override
    public Integer updateProcurement(Sto sto) {
        return procurementMapper.updateById(sto);
    }

    /**
     * 根据采购清单主键编号（id）来删除数据
     * @param id
     * @return
     */
    @Override
    public Integer deleteProcurement(Integer id) {
        return procurementMapper.deleteById(id);
    }

    /**
     * 根据传入的主键编号进行查询单条数据
     * @param id
     * @return
     */
    @Override
    public Sto queryProcurementById(Integer id) {
        return procurementMapper.queryProcurementById(id);
    }

    @Override
    public Integer getMaxProId() {
        LambdaQueryWrapper<Sto> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(Sto::getStoProId).orderByDesc(Sto::getStoProId).last("limit 1");
        return procurementMapper.selectOne(queryWrapper).getStoProId();
    }
}
